package com.zzw.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.zzw.utils.*;
import com.zzw.bean.Student;
import com.zzw.bean.Teacher;
import com.zzw.bean.User;
import com.zzw.service.imple.ITeacherService;
import com.zzw.service.imple.IUserService;


@Controller
public class TeacherController {
	@Autowired
	ITeacherService iTeacherService;
	
	/**
	 * 转发页面
	 * */
	@RequestMapping("/teacherList.do")
	@ResponseBody
	public ModelAndView teacherList(Teacher teacher) {
		ModelAndView mv=new ModelAndView();
		List<Teacher> list=iTeacherService.selectTeacher(teacher);
		mv.addObject("list",list);
		mv.setViewName("teacher_list");
		return mv;
	}
	
	/**
	 * 添加用户
	 * */
	@RequestMapping("addTeacher.do")
	@ResponseBody
	public Result addTeacher(Teacher teacher) {
		Result result=null;
		iTeacherService.addTeacher(teacher);
		result=ResultUtils.success();
		return result;
	}
	
	/**
	 * 添加用户
	 * */
	@RequestMapping("addContact.do")
	@ResponseBody
	public Result addContact(Teacher teacher) {
		Result result=null;
		iTeacherService.addContact(teacher);
		result=ResultUtils.success();
		return result;
	}
	
	/**
	 * 删除用户
	 * */
	@RequestMapping("deleteTeacher.do")
	@ResponseBody
	public Result deleteTeacher(Integer t_id) {
		Result result=null;
		iTeacherService.deleteTeacher(t_id);
		result=ResultUtils.success();
		return result;
	}
	
	/**
	 * id查询单个用于用户
	 * */
	@RequestMapping("/selectTeacherById.do")
	@ResponseBody
	public Result selectTeacherById(Integer t_id) {
		Result result=null;
		Teacher teacher=iTeacherService.selectTeacherById(t_id);
		result=ResultUtils.success(teacher);
		return result;
	}
	
	/**
	 * 更新单个用于用户
	 * */
	@RequestMapping("/updateTeacher.do")
	@ResponseBody
	public Result updateTeacher(Teacher teacher) {
		Result result=null;
		iTeacherService.updateTeacher(teacher);
		result=ResultUtils.success();
		return result;
	}

}
